@extends('layouts.admin')

@section('content')

<?php $pagename = '文章列表' ?>

<div class="admin-home">

<br>
<style>
td {
  text-align: center;
}
td img {
  width: 30px;
  height: 30px;
}
a:hover {
  text-decoration: none;
}
.panel.panel-info .logout {
    float: right;
    margin-top: 2px;
}
</style>  
<div class="panel panel-info">
  <div class="panel-heading">
    <h1 class="panel-title">
      <a href="{{ URL('admin/article-list') }}">
        《 后台首页
      </a>
      <div class="logout">
        <a href="{{ URL('logout') }}" onclick="event.preventDefault();document.getElementById('logout-form').submit();">
          注销
        </a>
        <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
          {{ csrf_field() }}
        </form>
      </div>
    </h1>
  </div>
  <div class="panel-body">
    @if ($errors->any())
      <div class="alert alert-danger">
        {{ implode('<br>', $errors->all()) }}
      </div>
    @endif
    <div class="col-xs-12" style="text-align: right; padding-right: 10px; margin-bottom: 10px;">
      <a href="{{ URL('admin/article-add') }}" class="btn btn-primary">添加</a>
    </div>
    <div class="col-xs-12">
      <table class="table">
        <thead>
          <tr>
            <th class="col-xs-4">描述</th>
            <th class="col-xs-2">类别</th>
            <th class="col-xs-1">是否展示</th>
            <th class="col-xs-2">作者</th>
            <th class="col-xs-2">发布时间</th>
            <th class="col-xs-1">操作</th>
          </tr>
        </thead>
        <tbody>
          @foreach ( $articles as $article)
            <tr>
              <td>{{ $article->describe }}</td>             
              <td>{{ $article->type }}</td>             
              <td>
                @if ( $article->enable == 1 )
                  是
                @else
                  否
                @endif
              </td>
              <td>{{ $article->author }}</td>          
              <td>{{ $article->created_at }}</td>          
              <td>
                <a href="{{ URL('admin/article-show/'.$article->id) }}" style="margin-right: 10px;">
                  <img src="{{ asset('image/support-edit.png') }}" alt="编辑" class="operate-img">
                </a> 
                <a href="#" onclick="deleteCase('{{ $article->id }}');" >
                  <img src="{{ URL('image/support-delete.png') }}" alt="删除" class="operate-img">
                </a>
              </td>             
            </tr>
          @endforeach        
        </tbody>
      </table>
    </div>
    <div class="col-xs-12 text-right">
      {{ $articles->links() }}
    </div>
  </div>
</div>

</div>


<script type="text/javascript">
var deleteCase = function(id)
{
  swal({
    title: "是否删除该文章",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "确认",
    cancelButtonText:"取消",
    closeOnConfirm: true
  }, function(){
    $.ajax({
      url: '{{ URL('admin/article-remove') }}'+'/'+id,
      method: 'POST',
      dataType: "json", 
      data:{_token: '{{ csrf_token() }}'},
      success: function(data) {
        window.setTimeout(function(){
          swal( "删除成功", "1 秒之后页面将自动跳转", "success");
          window.setTimeout(function() {
            location.reload();
          }, 1000);
        },500);
      },
      error: function() {
        swal("提交出错，请刷新o(╯□╰)o", "", "error")
      }
    });
  });
};
var createQRCode = function(self) {
  location.href = '/admin/support/qrcode?scene=' + $(self).val();
}
</script>

@stop